package org.example.easybuy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.easybuy.dao.UserDao;
import org.example.easybuy.entity.User;
import org.example.easybuy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public PageInfo<User> getUserPageInfo(Map<String, Object> params) {
        int pageNum=Integer.parseInt(params.get("pageNum").toString());
        int pageSize=Integer.parseInt(params.get("pageSize").toString());
        PageHelper.startPage(pageNum,pageSize,"createTime desc");
        return new PageInfo<>(userDao.selectUserByNameAndTime(params),3);
    }

    @Override
    public boolean deleteUser(int id) {
        return userDao.deleteUser(id)==1;
    }

    @Override
    public boolean registerUser(User user) {
        return userDao.registerUser(user)==1;
    }

    @Override
    public boolean updateUserPass(int id, String pass) {
        return userDao.updateUserPass(id,pass)==1;
    }

    @Override
    public boolean updateUser(User user) {
        return userDao.updateUser(user)==1;
    }

    @Override
    public User getUserByLoginName(String loginName) {
        return userDao.selectUserByLoginName(loginName);
    }

    @Override
    public boolean updateUserInfo(User user) {
        return userDao.updateUserInfo(user)==1;
    }
}
